package com.javaweb.admin.controller;

import com.javaweb.admin.entity.CodeRules;
import com.javaweb.admin.query.CodeRulesQuery;
import com.javaweb.admin.service.ICodeRulesService;
import com.javaweb.common.annotation.Log;
import com.javaweb.common.enums.LogType;
import com.javaweb.common.utils.JsonResult;
import com.javaweb.common.common.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 鲲鹏
 * @since 2020-12-23
 */
@RestController
@RequestMapping("/coderules")
public class CodeRulesController extends BaseController {

    @Autowired
    private ICodeRulesService codeRulesService;

    /**
     * 获取数据列表
     *
     * @param query 查询条件
     * @return
     */
    @GetMapping("/index")
    // @RequiresPermissions("coderules:index")
    public JsonResult index(CodeRulesQuery query) {
        return codeRulesService.getList(query);
    }

    /**
     * 添加记录
     *
     * @param entity 实体对象
     * @return
     */
    @Log(title = "", logType = LogType.INSERT)
    @PostMapping("/add")
    // @RequiresPermissions("coderules:add")
    public JsonResult add(@RequestBody CodeRules entity) {
        return codeRulesService.edit(entity);
    }

    /**
     * 获取详情
     *
     * @param coderulesId 记录ID
     * @return
     */
    @GetMapping("/info/{coderulesId}")
    // @RequiresPermissions("coderules:info")
    public JsonResult info(@PathVariable("coderulesId") Integer coderulesId) {
        return codeRulesService.info(coderulesId);
    }

    /**
     * 更新记录
     *
     * @param entity 实体对象
     * @return
     */
    @Log(title = "", logType = LogType.UPDATE)
    @PutMapping("/edit")
    // @RequiresPermissions("coderules:edit")
    public JsonResult edit(@RequestBody CodeRules entity) {
        return codeRulesService.edit(entity);
    }

    /**
     * 删除记录
     *
     * @param coderulesIds 记录ID
     * @return
     */
    @Log(title = "", logType = LogType.DELETE)
    @DeleteMapping("/delete/{coderulesIds}")
    // @RequiresPermissions("coderules:drop")
    public JsonResult delete(@PathVariable("coderulesIds") Integer[] coderulesIds) {
        return codeRulesService.deleteByIds(coderulesIds);
    }
}